package com.example.mymvvmdemo.net.presenter;


import com.example.mymvvmdemo.MyApplication;
import com.example.mymvvmdemo.net.model.IModel;
import com.example.mymvvmdemo.net.model.ImageModel;
import com.example.mymvvmdemo.net.view.IView;
import com.example.mymvvmdemo.utils.LogUtils;

import java.io.File;
import java.util.HashMap;

/**
 * 只具有一个body参数的post请求统一presenter
 */
public class ImagePresenter implements IModel.ImageModel {

    private ImageModel imageModel = new ImageModel(this);

    private IView.ImageView imageView;

    public ImagePresenter(IView.ImageView imageView) {
        this.imageView = imageView;
    }

    public void startLoadImage(String url, HashMap<String, String> hashMap, File imageFile, String name, String type) {
        imageModel.startLoadImage(url, MyApplication.getAuthToken(), hashMap, imageFile, name, type);
    }


    //回调给view
    @Override
    public void loadImageSuccess(String result, String type, int code) {
        LogUtils.d("load post image success type:" + type + ",result:" + result);
        LogUtils.printJson(result, type);
        imageView.loadImageSuccess(result, type, code);
    }

    @Override
    public void loadImageFail(String message, String type) {
        LogUtils.d("load post image success type:" + type + ",message:" + message);
        imageView.loadImageFail(message, type);
    }

    @Override
    public void loadImageAccountError(int code) {
        LogUtils.d("load post image account error code :" + code);
        imageView.loadImageAccountError(code);
    }

    @Override
    public void loadImageNetWorkError(String type) {
        LogUtils.d("load post image network error :" + type);
        imageView.loadImageNetWorkError(type);
    }

}
